|
How Do I Set the Baud-Rate for the 8051’s Dedicated UART? The Triscend E5 Configurable System-on-Chip (CSoC) device contains an embedded, accelerated 8051 microcontroller. The E5’s dedicated UART is directly compatible with the UART on the original 8051. One common question is how to set up the dedicated UART’s baud-rate generator. In modes 1 and 3, where the UART has an adjustable, variable baud rate, the UART uses either the 8051’s dedicated Timer 1 or Timer 2 as the baud-rate generator. The baud is determined by a few factors including … · the bus clock operating frequency, FBUSCLK · the desired baud rate, BAUD · the baud-rate generator divisor value, DIVISOR · the acceptable baud-rate error, %ERROR · The availability of either the 8051’s Timer 1 or Timer 2 dedicated timer/counter Timer 1 as the Baud-Rate GeneratorWhen using Timer 1 for the baud-rate generator, the 8-bit TH1 register stores the DIVISOR value. The maximum value for DIVISOR ≤ 255. Calculate the appropriate DIVISOR value using the following equation. Round the result up or down to the closest integer.
The actual baud rate generated using the DIVISOR value may be different than the desired baud rate, because DIVISOR is rounded to the nearest integer value.
The operating frequency and the integer value for DIVISOR may not provide the precise desired baud rate. Because each bit of the UART is oversampled and each data transaction re-synchronized, the UART tolerates slight errors in the baud rate, safely up to 3%. Calculate the percent baud-rate error using the following equation.
Timer 2 as the Baud-Rate GeneratorWhen using Timer 2 for the baud-rate generator, the 16-bit RCAP2 register stores the DIVISOR value. The maximum value for DIVISOR ≤ 65,535. Because Timer 2 has a 16-bit DIVISOR, it generates a wider variety of baud rates than Timer 1. Calculate the appropriate DIVISOR value using the following equation. Round the result up or down to the closest integer.
The 16-bit DIVISOR values is stored in a 16-bit register called RCAP2, which consists of two 8-bit registers called RCAP2H and RCAP2L RCAP2H is the most-significant byte and RCAP2L is the least-significant byte.
The actual baud rate generated using the DIVISOR value may be different than the desired baud rate, because DIVISOR is rounded to the nearest integer value.
The operating frequency and the integer value for DIVISOR may not provide the precise desired baud rate. Because each bit of the UART is oversampled and each data transaction re-synchronized, the UART tolerates slight errors in the baud rate, safely up to 3%. Calculate the percent baud-rate error using the following equation.
8051 UART “Magic” FrequenciesBecause of the UART hardware implementation, there are a few “magic” clock frequencies, FBUSCLK, that provide precise baud rate outputs—i.e. zero error—for common baud rates such as 4,800 bps, 9,600 bps, etc. These frequencies are any multiple of 1.8432 MHz, while the result is less than 40 MHz.
If you desire a precise baud rate, with zero error, and you have some flexibility in your operating frequency, the following tables includes some of the more commonly available crystal oscillators that operate at a “magic” frequency. Commonly Available Crystal Oscillators at
|
|
n |
Frequency |
|
2 |
3.6864 MHz |
|
6 |
11.0592 MHz |
|
10 |
18.432 MHz |
|
12 |
22.1184 MHz |
|
14 |
25.8048 MHz |
|
16 |
29.4912 MHz |
|
20 |
36.864 MHz |
The Excel spreadsheet associated with this article quickly calculates the DIVISOR for a given set of operating conditions.
|
Example: |
What is the DIVISOR value when operating at 25 MHz and the application requires a UART with a 38,400 bits per second baud rate? Should the application use Timer 1 or Timer 2 as the baud-rate generator? |
Open
the spreadsheet, and specify the E5’s operating clock frequency, which is 25
MHz in this example, or 25,000,000.
Specify
the desired baud, 38,400 bits per second. The spreadsheet immediately
calculates available solutions. For the spreadsheet calculations, any answer
that results in 3% error or less is considered a valid answer.

Under
the given operating conditions, there is no solution using Timer 1,
regardless if the SMOD bit.
There
is only one valid solution, using Timer 2. With RCAP2H loaded with 255
and RCAP2L loaded with 236, the 8051 UART communicates at 39,062.5
bits per second, which is within 1.73% of the desired baud rate
frequency.
After determining the baud rate values, you can either program the values directly via your application code or use FastChip’s graphical interface, as shown below.
With
FastChip open, click the UART button in the Dedicated Resources
section.

Choose
the serial port operating mode. Mode 1 or mode 3 is for a variable
baud rate.

The
transmitter and receiver baud rates can be different. In this example,
however, select Timer 2 as the baud-rate generator for both the
transmitter and receiver.
Scroll
down to Timer 2 Settings. The spreadsheet provides the DIVISOR values
in decimal. By default, FastChip uses hexadecimal. Click the radix buttons
next to the text boxes until the both display “Dec”.

Using
the values from the spreadsheet, enter 255 for RCAP2H and 236
for RCAP2L.
Click
OK. FastChip automatically creates an initialization routine based on
your settings. Clicking Generate from the FastChip toolbar creates an
initialization routine for your entire design. To view the initialization
routine for the UART, click UART to open the dialog box and then click View
Header.
|
FastChip Version: 2.2.0 This solution may or may not apply to other versions of the FastChip development system. |
®
© 2001 by Triscend Corporation. All rights reserved.